package cn.zxf.speedment_mysql.test_db.test_schema.position.generated;

import cn.zxf.speedment_mysql.test_db.test_schema.position.Position;
import cn.zxf.speedment_mysql.test_db.test_schema.position.PositionImpl;
import com.speedment.common.annotation.GeneratedCode;
import com.speedment.common.injector.annotation.ExecuteBefore;
import com.speedment.common.injector.annotation.WithState;
import com.speedment.runtime.config.identifier.TableIdentifier;
import com.speedment.runtime.core.component.sql.SqlPersistenceComponent;
import com.speedment.runtime.core.component.sql.SqlStreamSupplierComponent;
import com.speedment.runtime.core.exception.SpeedmentException;
import java.sql.ResultSet;
import java.sql.SQLException;
import static com.speedment.common.injector.State.RESOLVED;

/**
 * The generated Sql Adapter for a {@link
 * cn.zxf.speedment_mysql.test_db.test_schema.position.Position} entity.
 * <p>
 * This file has been automatically generated by Speedment. Any changes made to
 * it will be overwritten.
 * 
 * @author Speedment
 */
@GeneratedCode("Speedment")
public abstract class GeneratedPositionSqlAdapter {
    
    private final TableIdentifier<Position> tableIdentifier;
    
    protected GeneratedPositionSqlAdapter() {
        this.tableIdentifier = TableIdentifier.of("hellospeedment", "hellospeedment", "position");
    }
    
    @ExecuteBefore(RESOLVED)
    void installMethodName(@WithState(RESOLVED) SqlStreamSupplierComponent streamSupplierComponent, @WithState(RESOLVED) SqlPersistenceComponent persistenceComponent) {
        streamSupplierComponent.install(tableIdentifier, this::apply);
        persistenceComponent.install(tableIdentifier);
    }
    
    protected Position apply(ResultSet resultSet) throws SpeedmentException {
        final Position entity = createEntity();
        try {
            entity.setId(   resultSet.getLong(1)   );
            entity.setName( resultSet.getString(2) );
            entity.setDesc( resultSet.getString(3) );
        } catch (final SQLException sqle) {
            throw new SpeedmentException(sqle);
        }
        return entity;
    }
    
    protected PositionImpl createEntity() {
        return new PositionImpl();
    }
}